package lab1.db;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * 
 * @author Arty
 * 
 */

public class DatabaseManager {
	public DatabaseManager() {
		// dbConnect("jdbc:mysql://localhost:3306/app_db", "rootapp", "root");
	}

	public Connection getConnection() throws IOException {
		Properties props = new Properties();
		FileInputStream in = new FileInputStream("src/db.properties");
		props.load(in);
		in.close();

		String driver = props.getProperty("connection.driver_class");
		if (driver != null) {
			try {
				Class.forName(driver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		String url = props.getProperty("connection.url");
		url += props.getProperty("connection.default.schema");
		String username = props.getProperty("connection.username");
		String password = props.getProperty("connection.password");

		Connection con = null;
		try {
			con = DriverManager.getConnection(url, username, password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return con;
	}
}
